Page({
  data:{
    login:{
      user_id:""
    },
    username:"",
    password:""
  },
  onLoad:function(){
    this.data.login.user_id= wx.getStorageSync('user_id');
    if(this.data.login.user_id){
    console.log(this.data.login.user_id)
      wx.switchTab({
        url:"/pages/list/list"
      })
    }
  },
  login_FN:function(){
    var self=this;
    if(self.data.username==""||self.data.password==""){
      wx.showModal({
        "title":"提示",
        "content":"请输入用户名和密码！",
        "showCancel":false
      })
      return;
    }
    wx.showLoading({
      "mask":true,
    })
    wx.request({
      url: 'https://wx.ichelaba.com/htapi/index.php/user/user/loadLogin',//上线的话必须是https，没有appId的本地请求貌似不受影响
      data: {
        "user_name":self.data.username,
        "password":self.data.password
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res){
        console.log(res);
        if(res.data.result){
          wx.setStorageSync("user_id",res.data.user_id);
          wx.setStorageSync("user_name",res.data.user_name);
          wx.setStorageSync("user_img",res.data.head_img);
          wx.setStorageSync("user_point",res.data.point);
          wx.hideLoading();
          wx.showToast({
            "title":"登陆成功",
            "mask":true,
            complete:function(){
              wx.reLaunch({
                url:"/pages/list/list"
              })
            }
          })
        }else{
          wx.hideLoading();
          wx.showModal({
            "title":"提示",
            "content":res.data.message,
            "showCancel":false
          })
        }
        
        // wx.setStorageSync({
          
        // })
      },
      fail: function(e) {
        // _this.setData({
        //   aaa:e.error
        // })
      },
      complete: function(e) {
        // console.log(e)
        // complete
      }
    });
  },
  change_FN1:function(e){
    this.data.username=e.detail.value;
  },
  change_FN2:function(e){
    this.data.password=e.detail.value;
  }
})